package com.hyhy.hycloud.uaa.rpc.dubbo;

import com.hyhy.hycloud.uaa.exception.ExpiredVerificationCodeException;
import com.hyhy.hycloud.uaa.rpc.VerificationCodeServiceApi;
import com.hyhy.hycloud.uaa.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * VerificationCodeServiceApi Dubbo实现
 *
 * @author Xuegui Yuan
 * @date 2018-09-21
 */
@Service
public class VerificationCodeDubboService implements VerificationCodeServiceApi {


    @Autowired
    private VerificationCodeService verificationCodeService;

    @Override
    public boolean checkSmsVerificationCode(String bizCode, String mobile, String code, boolean removeAfterSuccess) {
        return verificationCodeService.checkSmsVerificationCode(bizCode, mobile, code, removeAfterSuccess);
    }

    @Override
    public Integer checkSmsVerificationCode(String bizCode, String mobile, String code) {
        try {
            if (verificationCodeService.checkSmsVerificationCode(bizCode, mobile, code)) {
                return 1;
            } else {
                return -1;
            }
        } catch (Exception e) {
            if (e instanceof ExpiredVerificationCodeException) {
                return 0;
            } else {
                return -1;
            }
        }

    }

}
